package com.twu.biblioteca;

import java.util.ArrayList;

public class Catalogue {

    ArrayList<Book> available_books = new ArrayList<Book>();
    ArrayList<Movie> available_movies = new ArrayList<Movie>();
    private int MIN_VALUE = 1;

    public void addBook(Book book) {
        available_books.add(book);
    }

    public int bookCount() {
        return available_books.size();
    }

    public String listBooks() {
        String output = "";
        for(Book book : available_books){
           output+= "<"+(available_books.indexOf(book)+ MIN_VALUE)+"> '"+ book.getTitle() +"' by "+book.getAuthor()+" : "+book.getSubjectArea()+"\n";
        }
        return output;
    }

    public void addMovie(Movie movie) {
        available_movies.add(movie);
    }

    public int movieCount() {
        return available_movies.size();
    }

    public String listMovies() {
        String output = "";
        for(Movie movie : available_movies){
            output+="<"+(available_movies.indexOf(movie)+ MIN_VALUE)+"> '"+movie.title+"' "+movie.year+" "+movie.director+" "+movie.rating+"\n";
        }
        return output;
    }

    public String checkIfAvailable(Book book) {
        for (Book available_book : available_books){
            if(book.getTitle().matches(available_book.getTitle()) && (book.getAuthor().matches(available_book.getAuthor())) )
                return "Book available in our catalogue!";
        }
        return "Sorry we don't have that book yet.";
    }

}
